<?php
/**
 * Created by PhpStorm.
 * User: 魏爷
 * Date: 2016/4/27
 * Time: 19:52
 */

namespace Home\Model;

class TradeModel extends BaseModel
{
    // 数据表名（不包含表前缀）
    protected $tableName        =   'user';

    /**
     * 获取用户所有信息
     * @param Integer $u_id 用户ID
     * @return array()
     **/
    public function getUserInfo($u_id)
    {
        return M('user as a')->join('wyz_usertype as b ON a.u_type_id=b.u_type_id', 'LEFT')->where("u_id=$u_id")->find();
    }
    /**
     * 用户管理修改
     * @param String $u_name  用户姓名
     * @param String $u_email  用户邮箱
     * @param Integer $u_age  用户年龄
     * @param Integer $u_sex  用户性别
     * @param Integer $u_tel  用户电话
     * @param String $u_address  用户地址
     * @param Integer $u_postcode  用户邮编
     * @param String $pictrueName  用户图片
     * @return boolean
    **/
    public function userManageSave($u_name, $u_email, $u_age, $u_sex, $u_tel, $u_address, $u_postcode, $pictrueName)
    {
        if (empty($pictrueName)) {
            $data['u_name']=$u_name;
            $data['u_email']=$u_email;
            $data['u_age']=$u_age;
            $data['u_sex']=$u_sex;
            $data['u_tel']=$u_tel;
            $data['u_address']=$u_address;
            $data['u_postcode']=$u_postcode;
            $u_id=getUserId();
            $res=$this->where("u_id=$u_id")->save($data);
            if ($res>=0) {
                return true;
            } else {
                return false;
            }
        }
        $data['u_name']=$u_name;
        $data['u_email']=$u_email;
        $data['u_age']=$u_age;
        $data['u_sex']=$u_sex;
        $data['u_tel']=$u_tel;
        $data['u_address']=$u_address;
        $data['u_postcode']=$u_postcode;
        $data['u_pic']=$pictrueName;
        $u_id=getUserId();
        $res=$this->where("u_id=$u_id")->save($data);
        if (!empty($res)) {
            return true;
        } else {
            return false;
        }
    }
    /**
     * 登陆密码修改
     * @param String $u_pwd_new  新生密码
     * @return boolean
    **/
    public function loginPasswordSave($u_pwd_new)
    {
        $u_id=getUserId();
        $data['u_pwd']=myMd5($u_pwd_new);
        $res=$this->where("u_id= $u_id")->save($data);
        if ($res===false) {
            return false;
        } else {
            return true;
        }
    }
}
